package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-09 00:14
 **/
public class LeetCode1629 {

    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int maxValue = 0;
        int maxIndex = 0;
        int n = releaseTimes.length;
        int pre = 0;
        for (int j = 0; j < n; j++) {
            if (releaseTimes[j] - pre > maxValue) {
                maxValue = releaseTimes[j] - pre;
                maxIndex = j;
            } else if (releaseTimes[j] - pre == maxValue && keysPressed.charAt(j) > keysPressed.charAt(maxIndex)) {
                maxIndex = j;
            }
            pre = releaseTimes[j];
        }

        return keysPressed.charAt(maxIndex);
    }

}
